gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\generalp\pnormal.m

    function pnormal(MI,SIGMA,I,afill,r,col)
%  pnormal(MI,SIGMA,I,afill,r,col)
%
% PNORAML vizualizes mixture of normal distributions in 2D space. 
%  Each normal distribution is determined by a pair of mean values and 
%  covariance matrix. The mean value is vizualized as a point and the 
%  covariance matrix as en ellipse. 
%
% Input:
%   MI [NxM] mean values for each class, MI=[mi_1,mi_2,...,mi_M]
%   SIGMA [Nx(MxN)] covariance matrices for each class,
%      SIGMA=[sigma_1,sigma_2,...,sigma_M].
%   I [1xK] contains class labels each pair.
%   afill [1x1] if is 1 then the ellipses will be filled otherwise
%      (default) will be outlined.
%   r [1x1] is a radius of the ellipses.
%
% See also PPOINTS, PNMIX.
%


% Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac
% (c) Czech Technical University Prague, http://cmp.felk.cvut.cz
% Written Vojtech Franc (diploma thesis) 10.11.1999, 23.12.1999
% Modifications:
% 23-mar-2001, V. Franc, written

hold on;

if nargin < 3 | isempty(I),
  I=ones(1,size(MI,2));
end

if nargin < 4 | isempty(afill),
  afill = 0;
end
  
DIM=size(MI,1);
K=size(MI,2);

if nargin < 5 | isempty(r),
  % determine appropriate radius for each ellipsoid so that they
  % do not overlap each other.
  
  r=inf*ones(1,K);
 
  for i=1:K,
    A=MI(:,i);
    isigma=inv(SIGMA(:,(i-1)*DIM+1:i*DIM));
    
    for j=1:K,
      if i~=j,
        B=MI(:,j);
         x=A+0.5*(B-A);      
         rcurr=sqrt( (x-A)'*isigma*(x-A));
         if rcurr < r(i),
           r(i)=rcurr;
         end
      end
    end
  end

  r=r*0.70;
  
else
  if length(r) ~= K,
    r=r*ones(1,K);
  end
end

for i=1:K,
  [x,y]=ellips(MI(:,i),SIGMA(:,(i-1)*DIM+1:DIM*i),r(i),30);

  if afill == 1,
    if nargin < 6, col = color(I(i)); end
    fill(x,y,col );
    plot(MI(1,i),MI(2,i),'xk');
  else
    if nargin < 6, col = color(I(i)); end
    plot(x,y,col);
    plot(MI(1,i),MI(2,i),sprintf('x%c',col ));
  end
  
end